const { query } = require("../db/query")

module.exports = {
  // 获取分类列表
  getCarouselList: async () => {
    // 调用query发送sql语句到mysql进行获取分类列表
    return await query("select * from carousel")
  },
  // 查询轮播图列表
  queryCarousel: async (start_time, end_time) => {
    // 调用query发送sql语句到mysql进行查询轮播图列表
    return await query("select * from carousel where start_time >=? and end_time <= ?", [start_time, end_time])
  },
  // 删除轮播图
  delCarousel: async (id) => {
    // 调用query发送sql语句到mysql进行删除轮播图
    return await query("delete from carousel where id =?", [id])
  },
  // 添加轮播图
  addCarousel: async (status, operate_place, start_time, end_time, swipe_image) => {
    // 调用query发送sql语句到mysql进行添加轮播图
    return await query("insert into carousel(status, operate_place, start_time, end_time, swipe_image) values(?,?,?,?,?)", [status, operate_place, start_time, end_time, swipe_image])
  },
  // 编辑回显
  findCarouselOfId: async (id) => {
    // 调用query发送sql语句到mysql进行查询轮播图
    return await query("select * from carousel where id =?", [id])
  },
  // 编辑轮播图
  editCarousel: async (id, status, operate_place, start_time, end_time, swipe_image) => {
    // 调用query发送sql语句到mysql进行编辑轮播图
    return await query("update carousel set status =?,operate_place =?,start_time =?,end_time =?,swipe_image =? where id =?", [status, operate_place, start_time, end_time, swipe_image, id])
  }
}